Socket
Socket
Sign inDemoInstall

skip-regex

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

skip-regex

Micro parser for detection of literal regexes


Version published
Weekly downloads
28K
increased by9.59%
Maintainers
1
Weekly downloads
 
Created
Source

npm Version License

skipRegex

Micro parser for detection of literal regexes.

Install

npm install skip-regex --save

Two formats:

  • CommonJS (ES5) for node and browserify-like bundlers.
  • ES6 module (ES6 untranspiled) for Rollup and the like.

How does it Works?

The start position must point to the first slash inside source (there's no error detection of this).

From there, sourceRegex will find with 99% accuracy the end of a regular literal expression from a start position in the given string.

The returned value is the position of the character following the regex, or start+1 if this is not a regex.

Example

import skipRegex from 'skip-regex'

//...
const start = source.indexOf('/')

if (~start) {
  const end = skipRegex(source, start)

  if (end > start + 1) { //looks like a regex
    const regex = source.slice(start, end)
    console.log(`Found regex ${regex} at position ${start}!`)
  }
}

Licence

MIT

Keywords

FAQs

Package last updated on 22 Jun 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc